package epsofts.Neutron;

/**
 * Mod�lise un coup, dans l'absolu. C'est donc au plateau d'�tre capable
 * d'accepter ou non un coup.
 * 
 * @version 1.0
 * @created 14-sept.-2006 22:47:43
 */
public class Coup
{

	/**
	 * Position d'origine du Neutron.
	 */
	private final short m_iNeutron_origine;

	/**
	 * Position finale du Neutron.
	 */
	private final short m_iNeutron_destination;

	/**
	 * Position d'origine de la bille boug�e.
	 */
	private final short m_iBille_origine;

	/**
	 * Position finale de la bille boug�e.
	 */
	private final short m_iBille_destination;

	public Coup(final Coup i_coup)
	{
		m_iBille_origine = i_coup.m_iBille_origine;
		m_iBille_destination = i_coup.m_iBille_destination;
		m_iNeutron_origine = i_coup.m_iNeutron_origine;
		m_iNeutron_destination = i_coup.m_iNeutron_destination;
	}
	
	private Coup()
	{
		m_iBille_origine = -1;
		m_iBille_destination = -1;
		m_iNeutron_origine = -1;
		m_iNeutron_destination = -1;
	}
	
	public Coup(final short i_bille_origine, final short i_bille_destination, final short i_neutron_origine, final short i_neutron_destination)
	{
		m_iBille_origine = i_bille_origine;
		m_iBille_destination = i_bille_destination;
		m_iNeutron_origine = i_neutron_origine;
		m_iNeutron_destination = i_neutron_destination;
	}
	
	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj)
	{
		if (obj instanceof Coup)
		{
			Coup i_coup = (Coup) obj;
			return (m_iBille_origine == i_coup.m_iBille_origine) && (m_iBille_destination == i_coup.m_iBille_destination) && (m_iNeutron_origine == m_iNeutron_origine) && (m_iNeutron_destination == m_iNeutron_destination);
		}
		else return false;
	}
	
	public boolean equals(Coup i_coup)
	{
		return (m_iBille_origine == i_coup.m_iBille_origine) && (m_iBille_destination == i_coup.m_iBille_destination) && (m_iNeutron_origine == m_iNeutron_origine) && (m_iNeutron_destination == m_iNeutron_destination);
	}

	public final short getNeutronOrigine()
	{
		return m_iNeutron_origine;
	}

	public final short getNeutronDestination()
	{
		return m_iNeutron_destination;
	}

	public final short getBilleOrigine()
	{
		return m_iBille_origine;
	}

	public final short getBilleDestination()
	{
		return m_iBille_destination;
	}
	
	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString()
	{
		return String.format("(%d -> %d ; %d -> %d)", m_iNeutron_origine, m_iNeutron_destination, m_iBille_origine, m_iBille_destination);
	}
	
	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode()
	{
		return toString().hashCode();
	}

	/**
	 * @return
	 */
	public Coup inverser()
	{
		return new Coup(((short) (24 - m_iBille_origine)), ((short) (24 - m_iBille_destination)), ((short) (24 - m_iNeutron_origine)), ((short) (24 - m_iNeutron_destination)));
	}

}
